﻿using System;
using System.Collections.Generic;
using FunctionalCLR.Core;

namespace Zove.Shell.Core.Function.Matrix {
    public sealed class MatrixUtils {

        public static double[] GetArray(List<object> list) {
            int m = list.Count;
            double[] n = new double[m];
            for (int i = 0; i < m; i++) {
                n[i] = Convert.ToDouble(list[i]);
            }

            return n;
        }

        public static double[,] GetMatrix(List<object> matrix) {
            int m = matrix.Count;
            int n = (matrix[0] as List<object>).Count;

            double[,] mtx = new double[m, n];
            for (int i = 0; i < m; i++) {
                List<object> row = matrix[i] as List<object>;
                for (int j = 0; j < n; j++) {
                    double result
                        = Convert.ToDouble(row[j]);
                    mtx[i, j] = result;
                }
            }

            return mtx;
        }
    }
}
